package com.yyx.app1.DiagnosticTools_function.Control.BiochemicalInfo;

import android.content.Context;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.yyx.app1.MedicationAssistant_function.Controls.Medication_Activity_Control.drup_listview.Medication_ListView_ItemView;
import com.yyx.app1.MedicationAssistant_function.Controls.Medication_Activity_Control.drup_listview.Medication_ListView_ItemView_;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by yuexing on 2015/9/30.
 */
public class BiochemicalInfo_Adapter extends BaseAdapter {
    private ArrayList<HashMap<String,String>> map;
    private Context context;

    public BiochemicalInfo_Adapter(Context context) {
        this.context = context;
    }

    public void findAll(JSONObject jsonObject)
    {
        map = new ArrayList<>();
        try {
            String[] name = new String[]{"中文名称","缩写","产生部位","概述","指标过高意义","指标过低意义"};
            String[] value = new String[name.length];
            value[0]=jsonObject.getString("chineseName");
            value[1]=jsonObject.getString("curtailment");
            value[2]=jsonObject.getString("position");
            value[3]=jsonObject.getString("summarize");
            value[4]=jsonObject.getString("highMean");
            value[5]=jsonObject.getString("lowMean");
            for (int i =0 ; i<name.length ;++i)
            {
                HashMap<String,String> one = new HashMap<>();
                one.put("k",name[i]);
                one.put("v",value[i]);
                map.add(i,one);
            }
        }
        catch (Exception e)
        {
           Log.e("异常1509302048", e.toString());
        }
    }

    @Override
    public int getCount() {
        return map.size();
    }

    @Override
    public Object getItem(int position) {
        return map.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Medication_ListView_ItemView it;
        if (convertView==null)
        {
            it = Medication_ListView_ItemView_.build(context);
        }
        else
        {
            it = (Medication_ListView_ItemView)convertView;
        }
        String str = map.get(position).get("v");
        it.bind(map.get(position).get("k"), Html.fromHtml(str).toString());
        return it;
    }
}
